const webpack = require("webpack");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const WebpackNotifier = require("webpack-notifier");
const plugins = require("./plugins");
const { resolve } = require("./utils");
const jsRules = require("./rules/jsRules");
const styleRules = require("./rules/styleRules");
const fileRules = require("./rules/fileRules");
module.exports = {
  mode: "development",
  stats: "errors-only",
  devtool: "eval-cheap-module-source-map",
  entry: {
    main: resolve("src/core/index.tsx"),
  },
  output: {
    path: resolve("build"),
    filename: "[name].js",
    publicPath: "/",
    pathinfo: false,
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js", ".jsx"],
    plugins: [
      new TsconfigPathsPlugin({
        configFile: resolve("tsconfig.json"),
      }),
    ],
  },
  plugins: [
    ...plugins,
    new WebpackNotifier({
      title: `sd`,
      alwaysNotify: true,
      excludeWarnings: true,
    }),
    new webpack.DefinePlugin({
      "process.env.BROWSER": true,
      "process.env.NODE_ENV": JSON.stringify("development"),
    }),
    new ReactRefreshWebpackPlugin({
      overlay: false,
    }),
    // new webpack.NamedModulesPlugin(),
    new webpack.WatchIgnorePlugin({
      paths: [resolve("server"), resolve("build"), resolve("dist")],
    }),
  ],
  optimization: {
    runtimeChunk: "single",
    minimize: false,
    splitChunks: false,
  },
  module: {
    rules: [...jsRules, ...styleRules, ...fileRules],
  },

  devServer: {
    historyApiFallback: true,
    static: {
      publicPath: "/",
      watch: true,
    },
    client: {
      overlay: true,
    },
    compress: true,
    hot: true,
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    host: "0.0.0.0",
    port: 8001,
  },
};
